/**
 * 
 */
package com.myworld.rocketmq;

import javax.annotation.Resource;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.myworld.MybootApplication;

/** 
 * @ClassName: MybootRocketMQProducer 
 * @Description:消息生产者
 * @author zhuqiang
 * @date 2018年12月29日 上午11:29:09 
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes=MybootApplication.class)
public class MybootRocketMQProducer {
	@Resource(name="jfMqMQProducer")
	private DefaultMQProducer jfMqMQProducer;
	/**
	 * mq topic
	 */
	@Value(value="${rocketmq.userIntegral.topic}")
	private String userProducerTopic;
	
	/**
	 * 生产者发送消息
	 */
	@Test
	public void sendRocketMQProducer() {
		Message msg =null;
		try {
			String mqTag="tag-A";//mq的tag
			msg = new Message(userProducerTopic,mqTag,"Hello RocketMQ".getBytes("utf-8"));
			this.jfMqMQProducer.send(msg);
			System.out.println("mq发送消息msg,topic:"+msg.getTopic()+",tag:"+msg.getTags()+",body:"+new String(msg.getBody(), "utf-8"));
			
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("mq发送消息msg,topic:"+msg.getTopic()+",tag:"+msg.getTags()+",异常:"+e.getMessage());
		}
	}

	

}
